package com.example.controller;

import com.example.pojo.*;
import com.example.service.problemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * ClassName:problemController
 * Description:
 *
 * @Author 赵永峰
 * @Create 2024/6/12 21:24
 * @Version 1.0
 */
@RestController
@Slf4j
public class problemController {
    @Autowired
    private problemService problemService;
    //插入一行，新增问题
    @PostMapping("/problemAdd")
    public Result problemAdd(@RequestBody problemPojo problemPojo){
        //插入一行数据
        problemService.insertOne(problemPojo);
        return Result.success();
    }
    //修改问题选项
    @PostMapping("/problemAddEdit")
    public Result problemAddEdit(@RequestBody problemPojo problemPojo){
        //插入一行数据
        problemService.problemAddEdit(problemPojo);
        return Result.success();
    }
    //加载时，筛选列表出来
    @PostMapping("/problemAllList")
    public Result problemAllList(){
        List<problemPojo> problemPojoList=problemService.problemAllList();
        return Result.success(problemPojoList);
    }
    //根据用户的条件，进行筛选
    @PostMapping("/problemAllListType")
    public Result problemAllListType(@RequestBody Map<String, Object> parameters) {
        List<problemPojo> problemPojoList= problemService.problemAllListType(parameters);
        return Result.success(problemPojoList);
    }
    //编辑问题，把问题保存到数据库中(富文本类）
    @PostMapping("/saveProblem")
    public Result saveProblem(@RequestBody Map<String, Object> parameters) {
        //向数据库中写入数据，根据id
        problemService.upDataField(parameters);
        return Result.success("保存成功");
    }
    //编辑问题，把问题保存到数据库中(数字类）
    @PostMapping("/saveProblemNmb")
    public Result saveProblemNmb(@RequestBody Map<String, Object> parameters) {
        //向数据库中写入数据，根据id
        problemService.upDataFieldNmb(parameters);
        return Result.success("保存成功");
    }
    //按照录入日期查询根据了不同的条件，有是不是我自己的，是不是未结题的，然后是那天录入的
    @PostMapping("/problemInputDateQuery")
    public Result problemInputDateQuery(@RequestBody Map<String, Object> parameters){
        List<problemPojo> problemPojoList=problemService.problemInputDateQuery(parameters);
        return Result.success(problemPojoList);
    }
    //上传问题描述位置照片的控制层
    @PostMapping("/describeAnnex")
    public Result describeAnnex(@RequestParam("file") MultipartFile file, @RequestParam Integer id, @RequestParam String describeAnnex) {

        String allName = problemService.describeAnnex(file,id,describeAnnex);
        return Result.success(allName);
    }
    //删除文件的函数
    @PostMapping("/describeRemove")
    public Result oilPictureRemove(@RequestBody Map<String, Object> parameters) {
        String fileName=problemService.oilPictureRemove(parameters);
        return Result.success(fileName);
    }

    //从新问题库中，查询某一个字段，等于多个值的数据
    @PostMapping("/inquiryProblemOneFindSeveralValProblemNew")
    public Result inquiryProblemOneFindSeveralValProblemNew(@RequestBody Map<String,Object> map){
        List<problemDataPojo> pojoList= problemService.inquiryProblemOneFindSeveralVal(map);
        return Result.success(pojoList);
    }
    //修改新问题库中的某一行，修改所有的字段
    @PostMapping("/editOneAllProblemWorkException")
    public Result editOneAllProblemWorkException(@RequestBody problemDataPojo pojo){
        problemService.editOneAll(pojo);
        return Result.success("修改成功");
    }
    //批量对问题索赔单的数据进行插入
    @PostMapping("/insertWarrantyListProblemManagement")
    public Result insertWarrantyListProblemManagement(@RequestBody List<warrantyClaimsPojo>  warrantyClaimsPojoList){
        problemService.insertWarrantyList(warrantyClaimsPojoList);
        return Result.success("批量插入成功");
    }
    //查询出所有的索赔信息
    @PostMapping("/inquiryWarrantyClaimAllProblemManagement")
    public Result inquiryWarrantyClaimAllProblemManagement(){
        List<warrantyClaimsPojo> list=problemService.inquiryWarrantyClaimAll();
        return Result.success(list);
    }
    //辅助函数，对售后索赔单的字段进行修改，根据id，修改多个字段，字段名称需要按照‘/’隔开，val也是一样的，并且需要和字段对应
    @PostMapping("/editWarrantyClaimFieldProblemManagement")
    public Result editWarrantyClaimFieldProblemManagement(@RequestBody Map<String,Object> map){
        problemService.editWarrantyClaimField(map);
        return Result.success("修改成功");
    }
    //辅助函数，根据id，向后端进行筛选问题库所有的数据
    @PostMapping("/inquiryProblemByIdProblemManagement")
    public Result inquiryProblemByIdProblemManagement(@RequestBody Map<String,Object> map){
        problemDataPojo pojo=problemService.inquiryProblemById(map);
        return Result.success(pojo);
    }
    //辅助函数，在索赔单中，查询出所有的IPTV问题，通过一个IPTV类型，找到所有不为空的数据
    @PostMapping("/inquiryWarrantyClaimOneFiledNoVoidProblemManagement")
    public Result inquiryWarrantyClaimOneFiledNoVoidProblemManagement(@RequestBody String filedName){
        List<warrantyClaimsPojo>  pojo= problemService.inquiryWarrantyClaimOneFiledNoVoid(filedName);
        return Result.success(pojo);
    }
    //辅助函数，在索赔单中，查询出用户指定的IPTV类型，指定的月份的数据，采用的是一个字段，等于多个值的方法,值需要用’/‘隔开，查询的都是字符串
    @PostMapping("/inquiryWarrantyClaimOneFiledSeveralProblemManagement")
    public Result inquiryWarrantyClaimOneFiledSeveralProblemManagement(@RequestBody Map<String,Object> map){
        List<warrantyClaimsPojo> pojos=problemService.inquiryWarrantyClaimOneFiledSeveral(map);
        return Result.success(pojos);
    }
    //辅助函数，在索赔单中，根据一个字段，查询出这个字段等于某一个值或者多个字的数据，值需要用’/‘隔开，用在查询int格式上
    @PostMapping("/inquiryWarrantyClaimOneFiledSeveralIntProblemManagement")
    public Result inquiryWarrantyClaimOneFiledSeveralIntProblemManagement(@RequestBody Map<String,Object> map){
        List<warrantyClaimsPojo> pojos=problemService.inquiryWarrantyClaimOneFiledSeveralInt(map);
        return Result.success(pojos);
    }

    //辅助函数：调取所有的不良品信息
    @PostMapping("/inquiryNoGoodPartAllProblemManagement")
    public Result inquiryNoGoodPartAllProblemManagement(){
        List<noGoodPartAssPojo> pojos=problemService.inquiryNoGoodPartAll();
        return Result.success(pojos);
    }
    //辅助函数：向后端的不合格品库中写入代码，需要写入多个字段
    @PostMapping("/editNoGoodDataFieldProblemManagement")
    public Result editNoGoodDataFieldProblemManagement(@RequestBody Map<String,Object> map){
        problemService.editNoGoodDataField(map);
        return Result.success("保存成功");
    }
    //辅助函数：查询零公里所有的数据
    @PostMapping("/inquiryZeroKilometersAllProblemManagement")
    public Result inquiryZeroKilometersAllProblemManagement(){
        List<zeroKilometersPojo> pojos=problemService.inquiryZeroKilometersAll();
        return Result.success(pojos);
    }
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），根据一个字段，查询等于该字段的所有数据,是整数型的，主要用于int
    @PostMapping("inquiryOneFieldZeroKilometersIntProblemManagement")
    public Result inquiryOneFieldZeroKilometersIntProblemManagement(@RequestBody Map<String,Object>map){
        List<zeroKilometersPojo> pojos=problemService.inquiryOneFieldZeroKilometersInt(map);
        return Result.success(pojos);
    }
    //辅助函数，对零部件的清单中，插入一行数据
    @PostMapping("/inertZeroKilometersOneProblemManagement")
    public Result inertZeroKilometersOneProblemManagement(@RequestBody zeroKilometersPojo pojo){
        problemService.inertZeroKilometersOne(pojo);
        return Result.success("修改成功");
    }
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），根据一个字段，查询等于该字段的所有数据,是字符串的
    @PostMapping("/inquiryOneFieldZeroKilometersProblemManagement")
    public Result inquiryOneFieldZeroKilometersProblemManagement(@RequestBody Map<String,Object> map){
        List<zeroKilometersPojo> pojos=problemService.inquiryOneFieldZeroKilometers(map);
        return Result.success(pojos);
    }
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），根据id，修改一行的多个字段，每个字段用’/‘隔开，内容同样用’/‘隔开，类型也用’/'隔开
    @PostMapping("/editZeroKilometersFieldProblemManagement")
    public Result editZeroKilometersFieldProblemManagement(@RequestBody Map<String,Object> map){
        problemService.editZeroKilometersField(map);
        return Result.success("修改成功");
    }
    //辅助函数：对不良品库中，根据一个字段，查询这个字段等于某一值，可以等于多个值，每个值中间有‘/’隔开；配的是类型；
    @PostMapping("/inquiryNoGoodFiledSeveralProblemManagement")
    public Result inquiryNoGoodFiledSeveralProblemManagement(@RequestBody Map<String,Object> map){
        List<noGoodPartAssPojo> pojos=problemService.inquiryNoGoodFiledSeveral(map);
        return Result.success(pojos);
    }
    //辅助函数：向后端IPTV报告中筛选数据，可以实现筛选多个等段同时等于多个数值，最多可以为10个。
    @PostMapping("/inquiryIptvReportSeveralFieldProblemManagement")
    public Result inquiryIptvReportSeveralFieldProblemManagement(@RequestBody Map<String,Object> map){
        List<iptvReportDataPojo> pojos=problemService.inquiryIptvReportSeveralField(map);
        return Result.success(pojos);
    }
    //插入一行IPTV报告，所有的字段都插入
    @PostMapping("/insertOneIptvReportProblemManagement")
    public Result insertOneIptvReportProblemManagement(@RequestBody iptvReportDataPojo pojo){
        problemService.insertOneIptvReport(pojo);
        return Result.success("插入成功");
    }
    //根据id，修改IptvReport中所有的数据
    @PostMapping("/editOneLineIptvReportProblemManagement")
    public Result editOneLineIptvReportProblemManagement(@RequestBody iptvReportDataPojo pojo){
        problemService.editOneLineIptvReport(pojo);
        return Result.success("修改成功");
    }
    //辅助函数：向后端IPTV报告中查询所有的数据
    @PostMapping("/inquiryIptvReportAllProblemManagement")
    public Result inquiryIptvReportAllProblemManagement(){
        List<iptvReportDataPojo> pojos=problemService.inquiryIptvReportAll();
        return Result.success(pojos);
    }
    //辅助函数，对零公里清单中（记录的不是零公里，是所有的问题），修改一行所有的数据
    @PostMapping("/editZeroKilometersOneAllByIdProblemManagement")
    public Result editZeroKilometersOneAllByIdProblemManagementNew(@RequestBody zeroKilometersPojo pojo){
        problemService.editZeroKilometersOneAllById(pojo);
        return Result.success("修改成功");
    }
    //辅助函数，在索赔单中，根据一个字段，查询这个字段的一个范围,用在查询字符串类型的，主要用在了查询文本格式保存的时间上
    @PostMapping("/inquiryWarrantyClaimOneFiledScopeStrProblemManagement")
    public Result inquiryWarrantyClaimOneFiledScopeStrProblemManagement(@RequestBody Map<String,Object> map){
        List<warrantyClaimsPojo> pojoList=problemService.inquiryWarrantyClaimOneFiledScope(map);
        return Result.success(pojoList);
    }
}
